# -*- coding: utf-8 -*-
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TuringClass.settings')
import django
from app_TuringClass.models import *

### Function: To update the QuestionList table while some questions were set UnApproved by admin
### How to use: admin run this script in Server backstage , like, [ python DB_QuestionList_update.py ] 
# 
# author: houchaoqun
# date: 2016/12/16
# 

def population():
	# update_QuestionList()
	# update_AnswerNum()


def update_QuestionList():
	print "[update_QuestionList] - running..."
	# questionList = QuestionList.objects.all()
	UnApprovedQuestion = QuestionDetails.objects.filter(QuestionStatus = 'UnApproved')
	for item in UnApprovedQuestion:
		if QuestionList.objects.filter(QuestionID = item.QuestionID).exists():
			QuestionList.objects.filter(QuestionID = item.QuestionID).delete()
			print "[ ",item.QuestionID,"] deleted successful..."


def update_AnswerNum():
	questionID_list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 16]
	answerNum_list =  [2, 3, 2, 2, 0, 1, 2, 6,  3,  3,  2,  0,  0]

	index = 0
	for item in questionID_list:
		answerNum = answerNum_list[int(index)]
		QuestionList.objects.filter(QuestionID = (int)(item)).update(AnswerNum=(int)(answerNum))
		index = index + 1


	
### main program
if __name__ == '__main__':
	print 'DB_QuestionList_update.py - running...'
	population()







	